package com.heima.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.mapper.TbVmMapper;
import com.heima.pojo.TbVmType;
import com.heima.pojo.vo.NodeVo;
import com.heima.pojo.vo.PageResponse;
import com.heima.pojo.vo.VendingMachineVo;
import com.heima.service.ITbVmService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TbVmServiceImpl extends ServiceImpl<TbVmMapper, TbVmType> implements ITbVmService {

    @Autowired
    private TbVmMapper vmMapper;

    /**
     * 设备搜索
     *
     * @param pageIndex
     * @param pageSize
     * @param innerCode
     * @return
     */
    @Override
    public PageResponse<VendingMachineVo> getByPage(Integer pageIndex, Integer pageSize, String innerCode) {
        Page<VendingMachineVo> page = new Page<>(pageIndex, pageSize);

        Page<VendingMachineVo> vendingMachineVoPage = vmMapper.getByPage(page, innerCode);
        PageResponse<VendingMachineVo> pageResponse = new PageResponse<>();
        pageResponse.setPageIndex(vendingMachineVoPage.getCurrent());
        pageResponse.setPageSize(vendingMachineVoPage.getSize());
        pageResponse.setTotalPage(vendingMachineVoPage.getPages());
        pageResponse.setTotalCount(vendingMachineVoPage.getTotal());
        pageResponse.setCurrentPageRecords(List.copyOf(vendingMachineVoPage.getRecords()));
        return pageResponse;
    }
}
